package com.itheima.exam.pojo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Result {
    private Integer code; // 编码：1成功，0和其它数字为失败
    private String msg; // 错误信息
    private Object data; // 数据

    /**
     * 返回成功
     *
     * @return Result
     */
    public static Result success() {
        return Result.builder()
                .code(1)
                .msg("success")
                .build();
    }

    /**
     * 返回成功
     *
     * @param object 返回数据
     * @return Result
     */
    public static Result success(Object object) {
        return Result.builder()
                .code(1)
                .msg("success")
                .data(object)
                .build();
    }

    /**
     * 返回失败
     *
     * @param msg 失败信息
     * @return Result
     */
    public static Result error(String msg) {
        return Result.builder()
                .code(0)
                .msg(msg)
                .build();
    }
}